class DataObject {
    constructor() {
      this.eventListeners = {}; // 存储事件监听器的对象
    }
  
    // 绑定事件监听器
    addEventListener(eventName, callback) {
      if (!this.eventListeners[eventName]) {
        this.eventListeners[eventName] = [];
      }
      this.eventListeners[eventName].push(callback);
    }
  
    // 触发事件
    dispatchEvent(eventName, eventData) {
      const listeners = this.eventListeners[eventName];
      if (listeners) {
        listeners.forEach(callback => {
          callback(eventData);
        });
      }
    }
  
    // 移除事件监听器
    removeEventListener(eventName, callback) {
      const listeners = this.eventListeners[eventName];
      if (listeners) {
        this.eventListeners[eventName] = listeners.filter(
          listener => listener !== callback
        );
      }
    }
  }
  
  // 创建一个数据对象实例
  const dataObj = new DataObject();
  
  // 添加事件监听器
  dataObj.addEventListener('custom', function(data) {
    console.log('Custom event triggered!');
    console.log(data);
  });
  
  // 触发自定义事件
  dataObj.dispatchEvent('custom', { message: 'This is a custom event.' });
  